package com.sx.zongzhi.presenter;

import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.bean.PopBusinessRoadBean;
import com.sx.zongzhi.bean.PopulationMoveDetailBean;
import com.sx.zongzhi.modle.CollectManager;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.utils.BaseUtil;
import com.sx.zongzhi.view.CommentView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by XZY on 2017/11/30.
 *流动人口新增/修改
 */
public class PopMoveAddPest {

    private CommentView commentView;

    public PopMoveAddPest(CommentView commentView) {
        this.commentView=commentView;
    }



    /**
     *
     * @param id 流动人口主键
     * @param path 地址
     * @param url 头像地址
     * @param businessList 业务信息
     * @param roadBeanList 铁路类的业务信息
     * @param detailBean 户籍人口详情
     */
    public void addPopMove(String path,String orgId,String id,String url,
                           List<String> businessList,List<PopBusinessRoadBean> roadBeanList,
                           PopulationMoveDetailBean detailBean){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("population.id",id);
        map.put("population.organization.id",orgId);
        map.put("population.idCardNo",detailBean.getIdCardNo());
        map.put("population.name",detailBean.getName());
        map.put("population.gender.id",detailBean.getGender().getId());
        map.put("population.birthday",detailBean.getBirthday());
        map.put("population.nation.id",detailBean.getNation().getId());
        map.put("population.politicalBackground.id",detailBean.getPoliticalBackground().getId());
        map.put("population.maritalState.id",detailBean.getMaritalState().getId());
        map.put("population.province",detailBean.getProvince());
        map.put("population.city",detailBean.getCity());
        map.put("population.district",detailBean.getDistrict());
        map.put("population.placeProvince",detailBean.getPlaceProvince());
        map.put("population.placeCity",detailBean.getPlaceCity());
        map.put("population.placeDistrict",detailBean.getPlaceDistrict());
        map.put("population.presentProvince",detailBean.getPresentProvince());
        map.put("population.presentCity",detailBean.getPresentCity());
        map.put("population.presentDistrict",detailBean.getPresentDistrict());
        map.put("population.nativePlaceAddress",detailBean.getNativePlaceAddress());
        map.put("population.isHaveHouse",detailBean.isIsHaveHouse());
        if (detailBean.isIsHaveHouse()){
            map.put("population.currentAddress",detailBean.getCurrentAddress());
        }else {
            map.put("population.noHouseReason",detailBean.getNoHouseReason());
        }
        map.put("population.mobileNumber",detailBean.getMobileNumber());
        map.put("population.telephone",detailBean.getTelephone());
        map.put("population.schoolStr",detailBean.getSchoolVal());
        map.put("population.career.id",detailBean.getCareer().getId());
        map.put("population.careerText",detailBean.getCareerText());
        map.put("population.residenceType.id",detailBean.getResidenceType().getId());
        map.put("population.usedName",detailBean.getUsedName());
        map.put("population.faith.id",detailBean.getFaith()!=null?detailBean.getFaith().getId():"");
        map.put("population.workUnit",detailBean.getWorkUnit());
        if (!BaseUtil.isEmpty(url)&&!url.startsWith("http")){
            map.put("population.fileStorage.path",url);
        }
        map.put("population.stayLocationType.id",detailBean.getStayLocationType().getId());
        map.put("population.inflowingReason.id",detailBean.getInflowingReason()!=null?
                detailBean.getInflowingReason().getId():"");
        map.put("population.registrationType.id",detailBean.getRegistrationType()!=null?
                detailBean.getRegistrationType().getId():"");
        map.put("population.certificateNumber",detailBean.getCertificateNumber());
        map.put("population.registerDate",detailBean.getRegisterDate());
        map.put("population.expectedDatedue",detailBean.getExpectedDatedue());
        map.put("population.isEmphasis",detailBean.getIsEmphasis());
        if (businessList!=null&&businessList.size()>0){
            for (int i=0;i<businessList.size();i++){
                map.put("populationTypes["+i+"]",businessList.get(i));
            }
        }
        if (roadBeanList!=null&&roadBeanList.size()>0){
            for (int i=0;i<roadBeanList.size();i++){
                map.put("alongRailways["+i+"].orgId",roadBeanList.get(i).getOrgId());
                map.put("alongRailways["+i+"].type",roadBeanList.get(i).getType());

            }
        }
        new CollectManager().addPopMove(path,map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                commentView.commentSuccess(response.getData());
            }
            @Override
            public void onFailures(String message) {
                commentView.showError(message);
            }
        });
    }

}
